bch(m4): ABLA replay + dynamic per-tip template size budget (M4 anchor) - #120
Merged
Conversation
Net-new BCH-specific validation slice (M1 §4.3, no btc/ analogue). CalculateASERT + GetNextASERTWorkRequired ported byte-exact from BCHN src/pow.cpp; anchors from chainparams.cpp (main/testnet3/testnet4). Governs SPV header-accept target only — PoW hash stays SHA256d, zero share-format / p2pool-merged-v36 surface change. Syntax-clean -std=c++20.
Port src/impl/btc/coin/header_chain.hpp to BCH: same store/sync/persistence and SHA256d PoW, with the one BCH divergence being difficulty. Replaces Bitcoin's 2016-block 2-week retarget with ASERT (aserti3-2d) by wiring validate_difficulty()/get_next_work_required() to asert.hpp (slice 18a). - BCHChainParams carries the ASERTParams anchor (asert.hpp) instead of a (timespan, spacing, interval) tuple; pow_limit/allow_min_difficulty mirror the anchor. mainnet/testnet3 genesis shared with Bitcoin (pre-fork); BCH testnet4 genesis flagged TODO-verify against VM300 bchn-bch chainparams. - validate_difficulty drops the ancestor-walk lookback (ASERT is anchor- absolute): trusts pre-anchor history and synthetic checkpoint seeds, else asserts header.nBits == get_next_work_required_asert(tip,...). - No p2pool-merged-v36 surface: ASERT governs header accept only, not the PoW hash or share format. Single-coin, src-only (no impl_bch CMake registration). Syntax-clean -std=c++20. Push held pending PR #106 ratification.
Standalone-parent commitment layout (BTC minus AuxPoW segment): [BIP34 height][/c2pool/][state_root 32B][TheMetadata]. BIP34 enforced per BCHN ContextualCheckBlock; no witness commitment (SegWit struck); CTOR handled separately by template tx sort; CashTokens transparent. Source-only header; shared by M4 GBT builder and the share validator.
…e 1)
Flesh out bch::coin::TemplateBuilder (was an M4 TODO stub) into a working
GBT assembler from HeaderChain + Mempool, mirroring the BTC builder with the
BCH consensus divergences:
* SHA256d merkle root + 50-BCH/210k-halving subsidy (== BTC curve).
* Next-block bits from the ASERT (aserti3-2d) DAA, not a 2016-block
retarget; falls back to tip bits / pow_limit below the ASERT anchor.
* CTOR (CHIP-2018-11): block body re-sorted to ascending txid after fee
selection, coinbase excluded.
* No SegWit: single canonical tx serialization, hash == txid, empty
segwit-free rules array. CashTokens carried transparently in tx bytes.
* EmbeddedCoinNode wired to build_template() for getwork().
Coinbase tx (and its s19 commitment) is still assembled downstream, as on
BTC; binding ../coinbase_commitment.hpp into the coinbase builder is the
next M4 slice. ABLA dynamic block-size and the rules array are pinned to
pre-ABLA 32 MB EB / empty here pending verification vs VM300 bchn-bch GBT
and the p2pool-merged-v36 python reference.
Source-only, -fsyntax-only clean. No impl_bch CMake registration (does not
race ci-steward); bch lane stays skip-green.
…sourcing
Add abla.hpp -- a 1:1 fixed-point port of BCHN consensus/abla.{h,cpp}
(pinned at v29.0.0): Config (MakeDefault/SetMax) + State (NextBlockState,
GetBlockSizeLimit). Mainnet grows; testnets fixed at 32 MB.
Route the template builder block-size byte budget through abla at the
activation/floor limit (32 MB) instead of a static constant. The floor is a
safe LOCAL build cap -- ABLA only ever raises it, so a template built to the
floor can never exceed the live consensus limit. Per-tip ABLA state replay
through the header chain (dynamic limit) is the next size-slice.
No p2pool-merged-v36 surface: ABLA governs only the block-size limit, not
PoW hash, share format, coinbase commitment, or PPLNS math.
Roundtrip exec: floor==32MB both nets; mainnet->41.3MB after 5000 full
blocks; testnet fixed. abla.hpp + template_builder.hpp -fsyntax-only OK.
Add abla::replay() -- replay ABLA State forward from a known-good anchor over a contiguous run of full-block sizes (1:1 BCHN State::NextBlockState loop). Wire TemplateBuilder::build_template to consume an optional caller- supplied per-tip ABLA State, using its GetBlockSizeLimit() as the dynamic block-size budget; absent it, fall back to the activation/floor limit (unchanged, always-safe LOCAL build cap). The per-block-size feed that drives replay is a full-block/embedded-daemon concern (M5+): the headers-only SPV header_chain structurally does not carry block sizes, so the dynamic limit is re-homed there rather than forced into the header chain. Build budget only -- zero p2pool-merged-v36 surface (no PoW hash, share format, coinbase commitment, or PPLNS touched). Validated: mainnet replay 5000x32MB grows 32->39.48MB (bounded by MAX_CONSENSUS_BLOCK_SIZE); testnet fixedSize stays 32MB; empty replay = anchor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
M4 anchor for the BCH embedded lane. BCH-only: every changed path is under src/impl/bch/ (+ bch tests + .github/workflows/build.yml target registration). Verified zero changes to other coin trees or shared src/core / src/impl/bitcoin_family.
6 commits on top of master (1040ede):
CI: all 6 coin smokes + bch embedded smoke green on the branch. Merge stays operator-gated.